package edu.tcc.iot.utils;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.ServiceLoader;

public class ServiceLocator {

	public static <T> T getInstance(Class<T> type){
		ServiceLoader<T> loader = ServiceLoader.load(type);
		Iterator<T> typeList = loader.iterator();
		if(typeList.hasNext()){
			return typeList.next();
		}
		throw new NoSuchElementException("The object of type " + type.getName() + " cannot be loaded.");
	}
}
